package com.huas.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringConfig implements ApplicationContextAware {
    private static ApplicationContext applicationContextDemo;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        applicationContextDemo = applicationContext;
    }

    public static <T> T getBean(Class<T> clazz){
        return applicationContextDemo.getBean(clazz);
    }
    public static <T> T getBean(String id,Class<T> clazz){
        return applicationContextDemo.getBean(id,clazz);
    }
    public static Object getBean(String name){
        return applicationContextDemo.getBean(name);
    }
}
